﻿Public Class Form1
    Dim AllowClose As Boolean = False

    Public Function Beenden()
        AllowClose = True
        Me.Close()
    End Function

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If ListBox1.SelectedItem = "Uhr" Then
            Uhr.Show()
            UhrToolStripMenuItem.Checked = True
        ElseIf ListBox1.SelectedItem = "Power Menü" Then
            Power_Menü.Show()
            PowerMenüToolStripMenuItem.Checked = True
        End If
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        If ListBox1.SelectedItem = "Uhr" Then
            Uhr.Close()
            UhrToolStripMenuItem.Checked = False
        ElseIf ListBox1.SelectedItem = "Power Menü" Then
            Power_Menü.Hide()
            PowerMenüToolStripMenuItem.Checked = False
        End If
    End Sub

    Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        If AllowClose = False Then
            e.Cancel = True
            Me.Hide()
        End If
    End Sub

    Private Sub UhrToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles UhrToolStripMenuItem.Click
        If UhrToolStripMenuItem.Checked = True Then
            Uhr.Show()
        Else
            Uhr.Close()
        End If
    End Sub

    Private Sub NotifyIcon1_MouseDoubleClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles NotifyIcon1.MouseDoubleClick
        Me.Show()
    End Sub

    Private Sub BeendenToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BeendenToolStripMenuItem.Click
        Me.Beenden()
    End Sub

    Private Sub PowerMenüToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PowerMenüToolStripMenuItem.Click
        If PowerMenüToolStripMenuItem.Checked = True Then
            Power_Menü.Show()
        Else
            Power_Menü.Close()
        End If
    End Sub
End Class
